#include <iostream>
#include <set>
#include <algorithm>
#include <iterator>
using std::set, std::cout, std::endl;
int main()
{
    set<int>A = {1, 2, 3};
    set<int>B = {2, 4};
    set<int>C1;
    set<int>C2;
    set<int>C3;
    set<int>C4;
    set<int>C5;
    set<int>C6;
    set<int>C7;
    set<int>::iterator pos;

    set_union(A.begin(),A.end(),B.begin(),B.end(),inserter( C1 , C1.begin() ) );    /*取并集运算*/
        //set_union(A.begin(),A.end(),B.begin(),B.end(),ostream_iterator<int>(cout," "));    /*取并集运算*/ //其中ostream_iterator的头文件是iterator
        cout<<"A u B = {";
        for(pos=C1.begin(); pos!=C1.end(); pos++)
        {
            if(pos!=C1.begin())cout<<", ";
            cout<<*pos;
        }
        cout<<"}"<<endl;
 
        set_intersection(A.begin(),A.end(),B.begin(),B.end(),inserter( C2 , C2.begin() ));    /*取交集运算*/
        cout<<"A n B = {";
        for(pos=C2.begin(); pos!=C2.end(); pos++)
        {
            if(pos!=C2.begin())cout<<", ";
            cout<<*pos;
        }
        cout<<"}"<<endl;
 
        set_difference( A.begin(), A.end(),B.begin(), B.end(),inserter( C3, C3.begin() ) );    /*取差集运算*/
        cout<<"A - B = {";
        for(pos=C3.begin(); pos!=C3.end(); pos++)
        {
            if(pos!=C3.begin())cout<<", ";
            cout<<*pos;
        }
        cout<<"}"<<endl;
 
        set_difference( B.begin(), B.end(),A.begin(), A.end(),inserter( C7, C7.begin() ) );    /*取差集运算*/
        cout<<"B - A = {";
        for(pos=C7.begin(); pos!=C7.end(); pos++)
        {
            if(pos!=C7.begin())cout<<", ";
            cout<<*pos;
        }
        cout<<"}"<<endl;
        set_difference(C1.begin(),C1.end(), A.begin(), A.end(),inserter( C4, C4.begin() ) );/*取差集运算*/
        cout<<"SA = {";
        for(pos=C4.begin(); pos!=C4.end(); pos++)
        {
            if(pos!=C4.begin())cout<<", ";
            cout<<*pos;
        }
        cout<<"}"<<endl;
 
        set_difference(C1.begin(),C1.end(), B.begin(), B.end(),inserter( C5, C5.begin() ) );/*取差集运算*/
        cout<<"SB = {";
        for(pos=C5.begin(); pos!=C5.end(); pos++)
        {
            if(pos!=C5.begin())cout<<", ";
            cout<<*pos;
        }
        cout<<"}"<<endl;
 
        set_symmetric_difference(A.begin(),A.end(),B.begin(),B.end(),inserter( C6 , C6.begin() ) );///取 对称差集运算
        cout<<"A ⊕ B = {";
        for(pos=C6.begin(); pos!=C6.end(); pos++)
        {
            if(pos!=C6.begin())cout<<", ";
            cout<<*pos;
        }
        cout<<"}"<<endl;

}